<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.yaodian100.core.common.utils.ServerValue" %>
<%@ page import="com.yaodian100.core.admin.utils.AdminHelper" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ include file="/taglibs.jsp" %>

<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>' />

<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.alphanumeric.js"></script>

<script language="javascript">
	$().ready(function(){
		$("#startGiftcardCode").numeric();
		$("#giftcardCount").numeric();
		
		$("#searchBtn").click(function(){
			if($("#startGiftcardCode").val()==""){
				alert("请输入卡号起始号码");
				return false;
			}else{
				if($("#startGiftcardCode").val().length!=11){
					alert("卡号起始号码格式错误");
					return false;
				}
			}
			
			if($("#giftcardCount").val()<=0){
				alert("请输入数量");
				return false;
			}
			
			$("#searchForm").submit();
		});
		
		$("#saveBtn").click(function(){
			if($("#receiveApplyUser").val()==""){
				alert("请输入申请人");
				return false;
			}
			
			if($("#receiveApplyDesc").val()==""){
				alert("请输入申请说明");
				return false;
			}
			
			$("#saveForm").submit();
		});
	});
</script>

<h1>礼品卡领用管理 - 领用申请</h1>

<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn"/><p />
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn"/><p />
</s:if>
<s:if test="hasFieldErrors()">
	<s:fielderror cssClass="msg rn"/><p />
</s:if>

<div class="f-link">
	<a href="${midContextPath}/giftcard/receiveList.do">回礼品卡领用管理查询列表页</a>
</div>

<s:form action="searchReceiveAdd.do" method="post" id="searchForm">
	<table class="tb-data" width="100%">	
		<tr>
			<th>连续号</th>
			<td>
				卡号起始号码：<input type="text" name="startGiftcardCode" id="startGiftcardCode" value="${startGiftcardCode}" size="15" maxlength="11" />
				数量：<input type="text" name="giftcardCount" id="giftcardCount" value="${giftcardCount}" size="10" value="0" />
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<input type="button" name="searchBtn" id="searchBtn" value="查询" />
				<input type="reset" value="复位" />
			</td>
		</tr>
	</table>
</s:form>
<br />
<s:form action="saveReceiveAdd.do" method="post" id="saveForm">
	<table class="tb-data" width="100%">	
		<tr>
			<th>申请人</th>
			<td>
				<input type="text" name="receiveApplyUser" id="receiveApplyUser" value="${receiveApplyUser}" size="10" maxlength="15" />
			</td>
		</tr>
		<tr>
			<th>领用人</th>
			<td>
				<%=AdminHelper.getUser().getUsername()%>
			</td>
		</tr>
		<tr>
			<th>连续号</th>
			<td>
				卡号起始号码：${startGiftcardCode}
				数量：${giftcardCount}
			</td>
		</tr>
		<tr>
			<th>申请说明</th>
			<td>
				<input type="text" name="receiveApplyDesc" id="receiveApplyDesc" value="${receiveApplyDesc}" maxlength="255" size="100" />
			</td>
		</tr>
	</table>
	<br />
	<c-rt:set var="receiveTotalCount" value='0' />
	<c-rt:set var="receiveTotalAmount" value='0' />
	<table width="100%">
		<thead class="tb-1">
			<tr>
				<th>礼品卡名称</th>
				<th>面额</th>
				<th>张数</th>
				<th>小计</th>
			</tr>
		</thead>
		<tbody class="tb-1">
			<c:forEach items="${receiveAddShowList}" var="showMap" varStatus="rows_index">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">
					<td>${showMap.GIFTCARD_NAME}</td>
					<td>${showMap.AMOUNT}</td>
					<input type="hidden" name="receiveItemAmounts" value="${showMap.AMOUNT}" />
					<td>${showMap.COUNT}</td>
					<input type="hidden" name="receiveItemCounts" value="${showMap.COUNT}" />
					<c-rt:set var="receiveTotalCount" value='${receiveTotalCount+showMap.COUNT}' />
					<td>${showMap.AMOUNT*showMap.COUNT}</td>
					<c-rt:set var="receiveTotalAmount" value='${receiveTotalAmount+(showMap.AMOUNT*showMap.COUNT)}' />
				</tr>
			</c:forEach>
		</tbody>
		<tr>
			<td colspan="2">
				总计张数：${receiveTotalCount}
			</td>
			<td colspan="2">
				总计金额：${receiveTotalAmount}
				<input type="hidden" name="receiveTotalAmount" value="${receiveTotalAmount}" />
			</td>
		</tr>
	<s:if test="receiveAddErrList.size==0 && receiveAddShowList.size>0">
		<tr>
			<td colspan="4">
				<input type="button" name="saveBtn" id="saveBtn" value="确定送出" />
			</td>
		</tr>
	</s:if>
	</table>
	<br />
	<table width="100%">
		<thead class="tb-1">
			<tr>
				<th>异常卡号</th>
				<th>异常原因</th>
			</tr>
		</thead>
		<tbody class="tb-1">
			<c:forEach items="${receiveAddErrList}" var="errMap" varStatus="rows_index">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">
					<td>${errMap.giftcardItemMap.CARD_CODE}</td>
					<td>${errMap.msg}</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</s:form>